//
//  WPNewFeatureCell.m
//  wobingwoyi
//
//  Created by WGP on 16/7/22.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPNewFeatureCell.h"
#import "WPTabBarController.h"
#import "AppDelegate.h"

#define STARTBTN_FONT 18
#define BOTTOM_MARGIN -160

@interface WPNewFeatureCell ()

@property(nonatomic,weak)UIImageView *bgImageView;
@property(nonatomic,weak)UIButton *startBtn;

@end

@implementation WPNewFeatureCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupSubviews];
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        [self setupSubviews];
    }
    return self;
}

-(void)setupSubviews
{
//    1.添加子控件
    UIImageView *bgImageView = [[UIImageView alloc] init];
    self.bgImageView = bgImageView;
    [self.contentView addSubview:bgImageView];
    
    UIButton *startBtn = [[UIButton alloc] init];
    self.startBtn = startBtn;
    

    [startBtn sizeToFit];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    [startBtn addTarget:self action:@selector(startBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:startBtn];
    
//    2.添加约束
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(SCREEN_HEIGHT*0.8);
        make.centerX.equalTo(self.contentView);
    }];
    
}

-(void)setIndex:(NSInteger)index
{
    _index = index;
    self.startBtn.hidden = YES;
    NSString *imageName = [NSString stringWithFormat:@"new_feature_%zd",index+1];
    self.bgImageView.image = [UIImage imageNamed:imageName];
}

#pragma mark - 开始按钮的动画方法
-(void)startAnimaton
{
    self.startBtn.transform = CGAffineTransformMakeScale(0, 0);
    self.startBtn.hidden = NO;
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:5 options:0 animations:^{
        
        
        self.startBtn.transform = CGAffineTransformIdentity;
        
    } completion:^(BOOL finished) {
        
    }];
}

#pragma mark startBtn的回调方法

-(void)startBtnDidClick
{
    
    WPTabBarController *tbc = [[WPTabBarController alloc] init];
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [delegate switchController:tbc];
    
}

@end







